Displaying what `history` line is current in bash prompt

Posted by warren on Super User See other posts from Super User or by warren
Published on 2010-05-07T12:56:03Z Indexed on 2010/05/07 13:00 UTC
Read the original article Hit count: 398

What formatting character needs to be added to a bash prompt to indicate the most recent history item run (or the current command number if 1 could be added to the last history entry)?

My prompt string is this:

\[\033[33m\][\u@\[\033[1;31m\]\h]\]\033[0m {\W}\n\033[1;34m\]\w\]\033[0m >

Gives me the following display:

[user@host] {~}
~ >

User is in yellow, and the host is in red. The entry in brackets is the current directory, and the entry before the greater-than sign is the full pwd.

Can I append to the first line the current command number so I would have something like the following:

[user@host] {~} (nnn)
~ >

where (nnn) is the current (or just processed) command number, as shown when running history?

© Super User or respective owner

Related posts about bash

Related posts about command-prompt